package com.example.store2024.controller;

import com.example.store2024.model.Category;
import com.example.store2024.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;
import java.util.Objects;

@Controller
public class CategoryController {
    private CategoryService categoryService;

    @Value("${store.static.site}")
    private String siteUrl;


    @Autowired
    public void setCategoryService(CategoryService categoryServic){
        this.categoryService=categoryServic;
    }

    @GetMapping("/category")
    public String list(Map<String, Object> model){
        List<Category> categories = this.categoryService.findAll();
        model.put("categories",categories);
        //将地址存储到请求域中
        model.put("site",siteUrl);

        return "list";
    }
}
